/*
* Copyright (C) 2012 Manuel Pérez
*
* This file is part of OpenSudoku.
*
* OpenSudoku is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenSudoku is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenSudoku. If not, see <http://www.gnu.org/licenses/>.
*
*/
package igraf.fakturak.javapdf;

//archivos
import igraf.Igraf;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
//librerias ajenas a itext
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
/**
 * @web http://jc-mouse.blogspot.com/
 * @author Mouse
 */
public class javapdf {
   
    private File gorde=null;
    
    public javapdf(){    
    }
    
    //itext erabiltzen duena
    public void crear_PDF(String t, String a, String s, String k, String c){
        //gordetzeko
        Colocar_Destino();
        
        if(this.gorde!=null){
            try {
                // Document instantzia
                Document mipdf = new Document();
                // pdf intantzia bat ezartzen da
                PdfWriter.getInstance(mipdf, new FileOutputStream(this.gorde + ".pdf"));
                mipdf.open();// 
                mipdf.addTitle(t); 
                mipdf.addAuthor(a); 
                mipdf.addSubject(s); 
                mipdf.addKeywords(k);  
                mipdf.add(new Paragraph(c)); 
                mipdf.close(); 
                JOptionPane.showMessageDialog(null,"PDF sortua");
            } catch (DocumentException ex) {
                Logger.getLogger(Igraf.class.getName()).log(Level.SEVERE, null, ex);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Igraf.class.getName()).log(Level.SEVERE, null, ex);
            }            
        }        
    }
    /*GORDETZEKO lehioa*/
    public void Colocar_Destino(){
       FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF fitxategia","pdf","PDF");
       JFileChooser fileChooser = new JFileChooser();       
       fileChooser.setFileFilter(filter);
       int result = fileChooser.showSaveDialog(null);
       if ( result == JFileChooser.APPROVE_OPTION ){   
           this.gorde = fileChooser.getSelectedFile().getAbsoluteFile();
        }
    }    
}